package demo.begin;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author DGW-PC
 * @data   2018年8月28日下午6:58:03
 * <a href="https://www.cnblogs.com/dgwblog/">我的博客</a>
 */
@Controller
public class SpringMvcRequestParm {

	

	private static Logger logger=Logger.getLogger(MvcRest.class.getName());
	
	private final String SUCCESS="success";
	
	
	/**
	 * 获取请求的Cookie 
	 * @param sessionid
	 * @return String
	 */
	@RequestMapping("/testCookieValue")
	public String testCookieValue(@CookieValue(value="JSESSIONID") String sessionid) {
		logger.log(Level.WARNING, "获取cookie id为"+sessionid);
		return SUCCESS;
	}
	
	
	/**
	 *  获取请求header
	 * @param info
	 * @return String
	 */
	@RequestMapping("/testRequestHeader")
	public String testRequestHeader(@RequestHeader(value="Accept:",defaultValue="chs") String info) {
		logger.log(Level.WARNING, "获取请求参数为"+info);
		return SUCCESS;
	}
	
	/**
	 * 获取请求请求参数
	 * @param username
	 * @param age
	 * @return String
	 */
	@RequestMapping("/testRequestParm")	
	public String testRequestParm(@RequestParam(value="username",required=true) String username,@RequestParam(value="age",defaultValue="0") Integer age ) {
		logger.log(Level.WARNING, "用户名"+username+"年龄"+age);
		return SUCCESS;
	}
	
}
